package com.lvmama.dashboard.rop.service.api;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.lvmama.dashboard.core.annotation.AjaxMethod;
import com.lvmama.dashboard.entity.ApiSummary;
import com.lvmama.dashboard.model.rop.AjaxRequest;
import com.lvmama.dashboard.model.rop.AjaxRequestBody;
import com.lvmama.dashboard.model.rop.AjaxResponse;
import com.lvmama.dashboard.model.rop.api.ApiInfo;
import com.lvmama.dashboard.model.rop.api.response.ApiInfoResponse;
import com.lvmama.dashboard.service.ajax.api.IApiInfoService;
import com.lvmama.dashboard.service.api.IApiSummaryService;
import com.lvmama.java.rhino.spark.utils.copy.CachedBeanCopier;

@Component("apiInfoService")
public class ApiInfoServiceImpl implements IApiInfoService {
	
	@Autowired
	private IApiSummaryService apiSummaryService;
	@Autowired
	private CachedBeanCopier beanCopier;
	
	@Override
	@AjaxMethod(ajaxmethod = "com.lvtu.dashboard.api.all")
	public AjaxResponse<ApiInfoResponse> queryAllApi(AjaxRequestBody<AjaxRequest> requestBody) {
		List<ApiSummary> apiSummaryList = apiSummaryService.queryApiSummaryList(1, 1000);
		
		AjaxResponse<ApiInfoResponse> responseBody = new AjaxResponse<ApiInfoResponse>();
		ApiInfoResponse response = new ApiInfoResponse();
		List<ApiInfo> list = beanCopier.copyList(apiSummaryList, ApiInfo.class);
		response.setList(list);
		responseBody.setData(response);
		
		return responseBody;
	}

}
